<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="button" value="获取数据" onclick="getData()"/>
<input type="button" value="发送数据" onclick="sendData()"/>
<p>解密前数据</p>
<div id="mydivBefore"></div>

<p>解密后数据</p>
<div id="mydivAfter"></div>
</body>
    <script src="webjars/jquery/3.3.1/jquery.min.js"></script>
    <script src="js/aes.js"></script>
    <script src="js/crypto-js.js"></script>
    <script src="js/pad-zeropadding.js"></script>
<script>
    function getData() {
        $.ajax({
            type: "GET",
            url:"/getDemo",
            success: function(resData) {
                console.log(resData);
                $("#mydivBefore").html(resData);
                $("#mydivAfter").html(Decrypt(resData))
            }
        });
    }

    function sendData() {
        alert("发送的数据："+Encrypt(JSON.stringify({id:"2",name:"尹吉欢"})));
        $.ajax({
            type: "POST",
            url:"/save",
            data:Encrypt(JSON.stringify({id:"2",name:"尹吉欢"})),
            dataType:'json',
            contentType: "application/json",
            success: function(resData) {
                alert("返回的数据："+resData);
                alert("解密之后："+Decrypt(resData));
                alert("解密之后转json对象："+JSON.parse(Decrypt(resData)).name);
            }
        });
    }

    var key = CryptoJS.enc.Utf8.parse("abcdef0123456789");
    function Encrypt(word) {
        var srcs = CryptoJS.enc.Utf8.parse(word);
        var encrypted = CryptoJS.AES.encrypt(srcs, key, {
            mode : CryptoJS.mode.ECB,
            padding : CryptoJS.pad.Pkcs7
        });
        return encrypted.toString();
    }

    function Decrypt(word) {
        var decrypt = CryptoJS.AES.decrypt(word, key, {
            mode : CryptoJS.mode.ECB,
            padding : CryptoJS.pad.Pkcs7
        });
        return CryptoJS.enc.Utf8.stringify(decrypt).toString();
    }

</script>
</html>